package com.zhyl.demo.service.impl;

import com.zhyl.demo.entity.Appointment;
import com.zhyl.demo.mapper.AppointmentMapper;
import com.zhyl.demo.mapper.PatientMapper;
import com.zhyl.demo.service.AppointmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Date;

/**
 * @author yang3
 */
@Service
public class AppointmentServiceImpl implements AppointmentService {

    private final AppointmentMapper appointmentMapper;
    private final PatientMapper patientMapper;

    @Autowired
    private AppointmentServiceImpl(AppointmentMapper appointmentMapper, PatientMapper patientMapper){
        this.appointmentMapper = appointmentMapper;
        this.patientMapper = patientMapper;
    }

    @Override
    public ArrayList<Appointment> loadAppointments(Integer patid) {
        ArrayList<Appointment> appointment= appointmentMapper.loadAppointments(patid);
        if (appointment!=null){
            return appointment;
        }else {
            return null;
        }
    }

    @Override
    public Boolean newAppointment(Appointment appointment) {
        if (appointment!=null){
            Integer i = appointmentMapper.newAppointment(appointment);
            if (i>0){
                return true;
            }else {
                return false;
            }
        }else {
            return false;
        }


    }

    @Override
    public Integer getNowDayAppointment(int docId, String time) {
        Integer nowDayAppointment = appointmentMapper.getNowDayAppointment(docId, time);
        if (nowDayAppointment!=null){
            return nowDayAppointment;
        }else {
            return 0;
        }
    }

    @Override
    public Integer updateAppointmentDetail(Appointment appointment) {
        Integer integer = appointmentMapper.updateAppointmentDetail(appointment);
        if (integer>=0){
            return 1;
        }else {
            return null;
        }
    }

    @Override
    public Appointment getAppointmentDetail(int id) {
        if (id<0){
            return null;
        }
        Appointment appointmentDetail = appointmentMapper.getAppointmentDetail(id);
        if (appointmentDetail!=null){
            return appointmentDetail;
        }else {
            return null;
        }
    }

    @Override
    public ArrayList<Appointment> getDocAppointment(int docId) {
        ArrayList<Appointment> docAppointment = appointmentMapper.getDocAppointment(docId);
        if (docAppointment!=null){
            return docAppointment;
        }else {
            return null;
        }
    }

    @Override
    public Boolean completeAppointment(int appointmentId) {
        if (appointmentId<1){
            return false;
        }
        Integer integer = appointmentMapper.completeAppointment(appointmentId);
        if (integer>=0){
            return true;
        }else {
            return false;
        }
    }

    @Override
    public Boolean callPatient(int id) {
        Integer integer = appointmentMapper.callPatient(id);
        if (integer>=0){
            return true;
        }else {
            return false;
        }
    }

    @Override
    public Boolean cancelCall(int id) {
        Integer integer = appointmentMapper.cancelCall(id);
        if (integer>=0){
            return true;
        }else {
            return false;
        }
    }

    @Override
    public Integer checkCall(int docId) {
        Integer integer = appointmentMapper.checkCall(docId);
        return integer;
    }

    @Override
    public ArrayList<Appointment> selectByDoc(int docId) {
        ArrayList<Appointment> appointments = appointmentMapper.selectByDoc(docId);
        if (appointments!=null){
            return appointments;
        }else {
            return null;
        }
    }

    @Override
    public ArrayList<Appointment> searchPatient(Integer patId, int docId) {
        ArrayList<Appointment> appointments = appointmentMapper.searchPatient(patId, docId);
        if (appointments!=null){
            return appointments;
        }else {
            return null;
        }
    }

    @Override
    public Boolean cancelAppointment(int appointmentId) {
        Integer i = appointmentMapper.cancelAppointment(appointmentId);
        return i >= 0;
    }

    @Override
    public Boolean deleteAppointment(int appointmentId) {
        Integer i = appointmentMapper.deleteAppointment(appointmentId);
        return i >= 0;
    }

    @Override
    public Boolean huayan(Integer appointmentId) {
        Integer huayan = appointmentMapper.huayan(appointmentId);
        return huayan>=0;
    }
}
